<template>
  <div class="progress-view">
    <div
      v-for="(item, index) in list"
      :key="index"
      class="item"
      :class="{ active: modelValue === item.value, cursor: isClick }"
      @click="handleClickItem(item)"
    >
      <div class="sign">{{ index + 1 }}</div>
      <div class="label">{{ item.label }}</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { PropType } from 'vue';

import { CommonObject } from '@/api/model/common';

const props = defineProps({
  list: {
    type: Array as PropType<CommonObject[]>,
    default: () => {
      return [];
    },
  },
  modelValue: {
    type: String,
    default: '',
  },
  isClick: {
    type: Boolean,
    default: false,
  },
});

const emits = defineEmits(['change', 'update:modelValue']);

const handleClickItem = (data: CommonObject) => {
  if (!props.isClick) return;

  const { value } = data;
  emits('change', value, data);
  emits('update:modelValue', value);
};
</script>

<style lang="less" scoped>
.progress-view {
  display: flex;
  align-items: center;
  justify-content: center;

  .item {
    display: flex;
    align-items: center;
    position: relative;

    & + .item {
      margin-left: 250px;

      &::before {
        content: '';
        height: 2px;
        width: calc(250px - 6px);
        background: #bbbdbf;
        position: absolute;
        left: calc(-250px + 2px);
        top: 50%;
        transform: translateY(-50%);
      }
    }

    &.cursor {
      cursor: pointer;
    }

    &.active {
      .sign {
        border-color: #2f51ff;
        background: #2f51ff;
      }

      .label {
        color: #31373d;
      }
    }

    .sign {
      width: 20px;
      height: 20px;
      border-radius: 10px;
      border: 1px solid #fff;
      background: #bbbdbf;
      font-size: 14px;
      color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .label {
      font-size: 14px;
      line-height: 18px;
      color: #bbbdbf;
      padding-left: 22px;
      position: relative;

      &::after {
        content: '';
        width: 16px;
        height: 2px;
        background: #d4d6d9;
        position: absolute;
        left: 2px;
        top: 50%;
        transform: translateY(-50%);
      }
    }
  }
}
</style>
